package com.common.controller.login;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.common.entity.RegisterUser;
import com.common.entity.User;
import com.common.service.UserService;

@Controller
public class RegisterController {
	
	@Resource
	private UserService userService;
	
	@RequestMapping(value="register",method=RequestMethod.GET)
	public String registerGet(){
		return "login/register";
	}
	
	@RequestMapping(value="register",method=RequestMethod.POST)
	public String registerPost(@ModelAttribute RegisterUser registerUser){
		User user = new User();
		user.setUsername(registerUser.getUsername());
		user.setPassword(registerUser.getPassword());
		userService.createUser(user);
		return "redirect:login";
	}
}
